package cn.ailanyin.home.module.login.controller;

import cn.ailanyin.home.common.entity.Result;
import cn.ailanyin.home.module.login.eneity.dto.LoginDTO;
import cn.ailanyin.home.module.login.eneity.dto.RegisterDTO;
import cn.ailanyin.home.module.login.service.LoginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录控制器
 *
 * @author ailanyin
 * @date 2024/04/13
 */
@Validated
@RestController
@RequiredArgsConstructor
@Tag(name = "登录管理")
public class LoginController {

    private final LoginService loginService;

    @PostMapping("/login")
    @Operation(summary = "登录")
    public Result<String> login(@RequestBody @Validated LoginDTO dto) {
        return Result.success(loginService.login(dto));
    }

    @PostMapping("/register")
    @Operation(summary = "注册")
    public Result register(@RequestBody @Validated RegisterDTO dto) {
        loginService.register(dto);
        return Result.success();
    }
}
